' "Ghost Game" by Charlie Veniot
' Based on the "40 Line Game Revised" by b+, mod of some game 2022⁣-⁣03⁣-⁣18 new way to score
_Title "Ghost Game"

Dim As Long sw, sh, goalR, hx, hy, i, hits, score, stars, nEnemies
sw = 640: sh = 480: nEnemies = 35: goalR = ⁣-⁣1: hx = 10: hy = 400 ' hero stuff (you)
ghostWidth% = 20
ghostHeight% = 18

Dim EX(nEnemies), EY(nEnemies), EC(nEnemies) As  Long ' enemy stuff
DIM eyeDirection%(nEnemies), ghostEyeball$(nEnemies), ghostIris$(nEnemies), irisColor&(nEnemies)

DIM MoveUpKey% = ASC("P"), MoveDownKey% = ASC("L"), MoveLeftKey% = ASC("A"), MoveRightKey%  = ASC("S")
PRINT "Keyboard keys used for movement:"
PRINT
PRINT "P for UP, L for DOWN, A for LEFT, S for RIGHT"
PRINT
PRINT "Are these okay?  Press the [N] key to redefine the movement key."
A$ = INPUT$(1)
IF UCASE$(A$) = "N" THEN GOSUB ⚙RedefineKeys
SLEEP

_INITAUDIO
SCREEN _NEWIMAGE(sw, sh, 32)

ghostBod$ = _
  ".......XXXXXX......." + _
  ".....XXXXXXXXXX....." + _
  "...XXXXXXXXXXXXXX..." + _
  "..XXXXXXXXXXXXXXXX.." + _
  ".XXXXXXXXXXXXXXXXXX." + _
  ".XXXXXXXXXXXXXXXXXX." + _
  ".XXXXXXXXXXXXXXXXXX." + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXXXXXXXXXXXXXXXXXXX" + _
  "XXX..XXXX..XXXX..XXX" + _
  "XX....XX....XX....XX" + _
  "XX....XX....XX....XX"
  
ghostEyeballLeft$ = _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  "..XXXX.....XXXX....." + _
  "XXXXXXX..XXXXXXX...." + _
  "X...XXX..X...XXX...." + _
  "X...XXX..X...XXX...." + _
  "X...XXX..X...XXX...." + _
  ".XXXXX....XXXXX....." + STRING$(8*20,".")
  
ghostEyeballRight$ = _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  ".....XXXX.....XXXX.." + _
  "....XXXXXXX..XXXXXXX" + _
  "....XXX...X..XXX...X" + _
  "....XXX...X..XXX...X" + _
  "....XXX...X..XXX...X" + _
  ".....XXXXXX...XXXXXX" + STRING$(8*20,".")
  
ghostIrisLeft$ = _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  ".XXX......XXX......." + _
  ".XXX......XXX......." + _
  ".XXX......XXX......." + STRING$(8*20,".")
  
ghostIrisRight$ = _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  "...................." + _
  ".......XXX......XXX." + _
  ".......XXX......XXX." + _
  ".......XXX......XXX." + STRING$(8*20,".")



For i = 1 To 1000
    PSet (Int(Rnd * sw), Int(Rnd * sh)), _RGB32(55 + Rnd * 200, 55 + Rnd * 200, 55 + Rnd * 200)
Next
PCOPY 0 , 1

For i = 1 To nEnemies
    EX(i) = Int(Rnd * (sw ⁣-⁣ 20) + 10): EY(i) = ⁣-⁣2 * sh * Rnd + sh: EC(i) = _RGB32(55 + Rnd * 200, 55 + Rnd * 200, 55 + Rnd * 200)
    eyeDirection% = INT(RND*2)
    ghostEyeball$(i) = IFF(eyeDirection%,ghostEyeballLeft$,ghostEyeballRight$)
    ghostIris$(i) = IFF(eyeDirection%,ghostIrisLeft$,ghostIrisRight$)
    irisColor&(i) = IFF(INT(RND*2), &h0000FF, &h964B00)
Next
     
Do
'    thisKey$ = inkey$
    Cls
    PCOPY 1, 0
    Print "Hits:"; hits, "Score:"; score
    Line (hx ⁣-⁣ 10, hy ⁣-⁣ 10)⁣-⁣Step(20, 20), &hFFFF00, B
    If hx >= sw ⁣-⁣ 13 And goalR Then score = score + 100: goalR = 0
    If hx <= 13 And goalR = 0 Then score = score + 100: goalR = ⁣-⁣1
    For i = 1 To nEnemies ' the enemies
       ' Circle (EX(i), EY(i)), 10, EC(i)
       FOR thisY = 1 TO ghostHeight%
            FOR thisX = 1 TO ghostWidth%
                IF MID$(ghostBod$, (thisY⁣-⁣1) * ghostWidth% + thisX, 1) <> "." THEN PSET (EX(i)+thisX, EY(i)+thisY), EC(i)
                IF MID$(ghostEyeball$(i), (thisY⁣-⁣1) * ghostWidth% + thisX, 1) <> "." THEN PSET (EX(i)+thisX, EY(i)+thisY), &hFFFFFF
                IF MID$(ghostIris$(i), (thisY⁣-⁣1) * ghostWidth% + thisX, 1) <> "." THEN PSET (EX(i)+thisX, EY(i)+thisY), irisColor&(i)
            NEXT thisX
        NEXT thisY
        If Sqr((EX(i) + 10 ⁣-⁣ hx) ^ 2 + (EY(i) + 9 ⁣-⁣ hy) ^ 2) < 20 Then 'collision
            Sound 2000, 3: hits = hits + 1
            EX(i) = Int(Rnd * 600 + 20): EY(i) = ⁣-⁣_Height * Rnd ' move that bad boy!
            If hits = 10 Then Print "Too many hits, goodbye!": _Delay 10
        End If
        EY(i) = EY(i) + Int(Rnd * 5)
        If EY(i) > 461 Then EX(i) = Int(Rnd * 600 + 20): EY(i) = ⁣-⁣sh * Rnd
    Next
    If KEYSTATE(MoveDownKey%) Then hy = hy + 2
    If KEYSTATE(MoveUpKey%) Then hy = hy ⁣-⁣ 2
    If KEYSTATE(MoveLeftKey%) Then hx = hx ⁣-⁣ 2
    If KEYSTATE(MoveRightKey%) Then hx = hx + 2
    If hx < 10 Then hx = 10
    If hx > sw ⁣-⁣ 10 Then hx = sw ⁣-⁣ 10
    If hy < 10 Then hy = 10
    If hy > sh ⁣-⁣ 10 Then hy = sh ⁣-⁣ 10
    _Display
Loop 


⚙RedefineKeys:
WHILE keyState(): WEND
CLS
PRINT "Redefine keys for movement."
PRINT
PRINT "Press (and then release) a keyboard key for the moving UP action."
DO : MoveUpKey% = keyState() : LOOP WHILE MoveUpKey% = 0
WHILE keyState(): WEND

' DIM MoveUpKey% = ASC("P"), MoveDownKey% = ASC("L"), MoveLeftKey% = ASC("A"), MoveRightKey%  = ASC("S")
RETURN